import uvicorn
from fastapi import FastAPI
from dynaconf import Dynaconf
from app.api import router as api_router
from app.exception.handlers import register_exception_handlers

# 加载配置
settings = Dynaconf(
    settings_files=['config/config.yaml'],
    environments=True
)

app = FastAPI(
    title=settings.app.name,
    version=settings.app.version,
    debug=settings.app.debug
)

# 注册API路由
app.include_router(api_router)

# 注册全局异常处理器
register_exception_handlers(app)

@app.get("/")
async def root():
    """健康检查接口"""
    return {
        "code": 0,
        "errorMsg": "",
        "data": {
            "status": "ok",
            "version": settings.app.version
        }
    }

if __name__ == "__main__":
    uvicorn.run(
        "main:app",
        host=settings.server.host,
        port=settings.server.port,
        reload=settings.app.debug
    )
